<#assign tit><#if _oper='add'>新增<#else>修改</#if>卡种</#assign>
<@page.html title=tit>
<script type="text/javascript" src="${_appPath!}/js/cal.js"></script>
<script type="text/javascript">
  var sl_days = '<select><option value=""></option><#if dayCode??><#list dayCode as t><option value="${t.id}">${t.name}</option></#list></#if></select>';
  var sl_lvs = '<select style="width:200px;"><option value=""></option><#if shopLevel??><#list shopLevel as t><option value="${t.id}">${t.id} - ${t.name}</option></#list></#if></select>';
  var sl_uts = '<select><option value=""></option><#if useType??><#list useType as t><option value="${t.id}">${t.name}</option></#list></#if></select>';
  var ss_del = '<img src="${_appPath!}/images/del.png" onclick="deli(this);" style="cursor:pointer;"/>';

  function deli(e) {
    var tr = e.parentNode.parentNode;
    var aid = tr.getAttribute("aid");
    if(aid)
      tr.style.display = "none";
    else
      tr.parentNode.deleteRow(tr.rowIndex);
  }
  function addtm() {
    var tb = getEl("tb_time");
    if(!tb) return;
    var tr = tb.insertRow(-1);
    tr.className = (tb.rows.length%2?"line1":"line2");
    var td = tr.insertCell(-1);
    td.innerHTML = sl_days;
    td = tr.insertCell(-1);
    td.innerHTML = '<select><option value="1">限制</option><option value="2">不限制</option></select>';
    td = tr.insertCell(-1);
    td.innerHTML = '<input type="text" value="00:00" size="5" maxlength="5">';
    td = tr.insertCell(-1);
    td.innerHTML = '<input type="text" value="23:59" size="5" maxlength="5">';
    td = tr.insertCell(-1);
    td.innerHTML = ss_del;
    tb.parentNode.scrollTop = 9999;
  }
  function addlv() {
    var tb = getEl("tb_level");
    if(!tb) return;
    var tr = tb.insertRow(-1);
    tr.className = (tb.rows.length%2?"line1":"line2");
    var td = tr.insertCell(-1);
    td.className = "left";
    td.innerHTML = sl_lvs;
    td = tr.insertCell(-1);
    td.innerHTML = '<input type="text" value="1.00" size="8" maxlength="8">';
    td = tr.insertCell(-1);
    td.innerHTML = ss_del;
    tb.parentNode.scrollTop = 9999;
  }
  function addqn() {
    var tb = getEl("tb_quan");
    if(!tb) return;
    var tr = tb.insertRow(-1);
    tr.className = (tb.rows.length%2?"line1":"line2");
    var td = tr.insertCell(-1);
    td.innerHTML = '<input type="text" value="" size="8" maxlength="6">';
    td = tr.insertCell(-1);
    td.innerHTML = '<input type="text" value="" size="8" maxlength="6">';
    td = tr.insertCell(-1);
    td.innerHTML = '<input type="text" value="1.00" size="8" maxlength="8">';
    td = tr.insertCell(-1);
    td.innerHTML = ss_del;
    tb.parentNode.scrollTop = 9999;
  }
  function addus() {
    var tb = getEl("tb_user");
    if(!tb) return;
    var tr = tb.insertRow(-1);
    tr.className = (tb.rows.length%2?"line1":"line2");
    var td = tr.insertCell(-1);
    td.innerHTML = sl_uts;
    td = tr.insertCell(-1);
    td.innerHTML = '<input type="text" value="1" size="4" maxlength="4">';
    td = tr.insertCell(-1);
    td.innerHTML = '<input type="text" value="" size="8" maxlength="8">';
    td = tr.insertCell(-1);
    td.innerHTML = '<label><input type="checkbox" value="1">是</label>';
    td = tr.insertCell(-1);
    td.innerHTML = ss_del;
    tb.parentNode.scrollTop = 9999;
  }

  function save(fm) {
    if(!dotbd(fm.times, "tb_time", ["日期","状态","开始时间","结束时间"])) return false;
    if(!dotbd(fm.levels, "tb_level", ["门店级别","折扣"])) return false;
    if(!dotbd(fm.quans, "tb_quan", ["数量下限","数量上限","折扣"])) return false;
    if(!dotbd(fm.manyus, "tb_user", ["使用人类型","使用人数量","增加费用/人",""])) return false;
    return post(fm);
  }
  function dotbd(ipt, tbid, cl) {
    var tb = getEl(tbid);
    if(!tb) return false;
    var i, j, aid, el, ss, tr, arr = [];
    for(j=0; j<tb.rows.length; j++) {
      tr = tb.rows[j];
      aid = tr.getAttribute("aid");
      if(tr.style.display=="none") {
        if(aid) arr.push(aid+",-");
      } else {
        for(i=0; i<cl.length; i++) {
          el = tr.cells[i].firstChild;
          if(el.tagName=="INPUT" && (el.type=="radio" || el.type=="checkbox")) {
            continue;
          }
          if(el.value=="" && cl[i]!="") {
            window.alert("请"+(el.tagName=="SELECT"?"选择":"输入")+cl[i]);
            try {el.focus();} catch(e) {}
            return false;
          }
        }
        ss = aid?aid:"";
        for(i=0; i<cl.length; i++) {
          ss += ",";
          el = tr.cells[i].firstChild;
          if(!(el.tagName=="INPUT" && (el.type=="radio" || el.type=="checkbox") && !el.checked))
            ss += el.value;
        }
        arr.push(ss);
      }
    }
    ipt.value = arr.join("|");
    return true;
  }
</script>
<div style="width:480px; float:left;">

  <form id="fm_input" method="post" action="<#if _oper='add'>_add<#else>_edit</#if>" onsubmit="return save(this);">
    <input type="hidden" name="times" value="">
    <input type="hidden" name="levels" value="">
    <input type="hidden" name="quans" value="">
    <input type="hidden" name="manyus" value="">
    <div class="kbox">
      <table class="input">
        <caption>基本信息</caption>
        <tr>
          <th width="18%">编号</th>
          <td width="29%"><#if _oper='add'><input type="text" name="code" value="${cardType.code!}" req="编号" size="10" maxlength="10"><#else><input type="hidden" name="code" value="${cardType.code!}">${cardType.code!}</#if></td>
          <th width="18%">卡种标识</th>
          <td width="34%"><input type="text" name="markId" value="${cardType.markId!}" size="10" maxlength="10"></td>
        </tr>
        <tr>
          <th>名称</th>
          <td colspan="3"><input type="text" name="chName" value="${cardType.chName!}" req="名称" size="38" maxlength="50"></td>
        </tr>
        <tr>
          <th>大类</th>
          <td><select name="typeId"><#if cardClass??><#list cardClass as t><option value="${t.id}"<#if cardType.typeId?? && cardType.typeId=t.id> selected</#if>>${t.name}</option></#list></#if></select></td>
          <td colspan="2" style="line-height:120%;"><label><input type="checkbox" name="saleType1" value="1"<#if cardType.saleType1?? && cardType.saleType1=1> checked</#if>>新合同</label>
            <label><input type="checkbox" name="saleType2" value="1"<#if cardType.saleType2?? && cardType.saleType2=1> checked</#if>>升级</label>
            <label><input type="checkbox" name="saleType3" value="1"<#if cardType.saleType3?? && cardType.saleType3=1> checked</#if>>续会</label>
            <label style="display:inline-block;"><input type="checkbox" name="preferRenewal" value="1"<#if cardType.preferRenewal?? && cardType.preferRenewal=1> checked</#if>>优惠续会</label>
            <label style="display:inline-block;"><input type="checkbox" name="promotionCard" value="1"<#if cardType.promotionCard?? && cardType.promotionCard=1> checked</#if>>营销活动</label>
            <label style="display:inline-block;"><input type="checkbox" name="baosteelUse" value="1"<#if cardType.baosteelUse?? && cardType.baosteelUse=1> checked</#if>>宝钢专用</label></td>
        </tr>
        <tr>
          <th>通店区域</th>
          <td colspan="3"><select name="manyShop" style="width:315px;"><option value=""></option><#if cardArea??><#list cardArea as t><option value="${t.id}"<#if cardType.manyShop?? && cardType.manyShop=t.id> selected</#if>>${t.id} - ${t.name}</option></#list></#if></select></td>
        </tr>
        <tr>
          <th>启用日期</th>
          <td><input type="text" name="activeTime" value="${cardType.activeTime!}" onclick="cal(this);" req="启用日期" size="10" maxlength="10"></td>
          <th>禁用日期</th>
          <td><input type="text" name="inactiveTime" value="${cardType.inactiveTime!}" onclick="cal(this);" req="禁用日期" size="10" maxlength="10"></td>
        </tr>
        <tr>
          <td colspan="4" style="line-height:120%;"><label><input type="checkbox" class="cb" name="manyUser" value="1"<#if cardType.manyUser?? && cardType.manyUser=1> checked</#if>>多人卡</label>
            <label><input type="checkbox" class="cb" name="tasteCard" value="1"<#if cardType.tasteCard?? && cardType.tasteCard=1> checked</#if>>体验卡种</label>
            <label><input type="checkbox" class="cb" name="directorCard" value="1"<#if cardType.directorCard?? && cardType.directorCard=1> checked</#if>>董事卡</label>
            <br>
            <label><input type="checkbox" class="cb" name="allowUpdate" value="1"<#if cardType.allowUpdate?? && cardType.allowUpdate=1> checked</#if>>允许升级</label>
            <label><input type="checkbox" class="cb" name="fixedType" value="1"<#if cardType.fixedType?? && cardType.fixedType=1> checked</#if>>升级固定卡种</label>
            <label><input type="checkbox" class="cb" name="makeCard" value="1"<#if cardType.makeCard?? && cardType.makeCard=1> checked</#if>>允许在门店制卡</label></td>
        </tr>
        <tr>
          <th>统计类别</th>
          <td colspan="3"><select name="category" style="width:315px;"><option value=""></option><#if cardCategory??><#list cardCategory as t><option value="${t.id}"<#if cardType.category?? && cardType.category=t.id> selected</#if>>${t.id} - ${t.name}</option></#list></#if></select></td>
        </tr>
        <tr>
          <th>财务分类</th>
          <td colspan="3"><select name="traCode" style="width:315px;"><option value=""></option><#if tranCode??><#list tranCode as t><option value="${t.tranCode}"<#if cardType.traCode?? && cardType.traCode=t.tranCode> selected</#if>>${t.tranCode} - ${t.codeName}</option></#list></#if></select></td>
        </tr>
        <tr>
          <th>备注</th>
          <td colspan="3"><textarea name="note" cols="38" rows="2">${cardType.note!}</textarea></td>
        </tr>
      </table>

      <table class="input">
        <caption style="margin-top:20px; padding-top:10px; border-top:1px solid #ccc;">限制设置</caption>
        <tr>
          <th width="22%">有效期</th>
          <td width="25%"><input type="text" name="valids" value="${cardType.valids!}" req="有效期" size="8" maxlength="6"></td>
          <th width="13%">单位</th>
          <td width="40%"><select name="validUnit"><#if timeUnit??><#list timeUnit as t><option value="${t.id}"<#if cardType.validUnit?? && cardType.validUnit=t.id> selected</#if>>${t.name}</option></#list></#if></select></td>
        </tr>
        <tr>
          <th>赠送有效期</th>
          <td><input type="text" name="addValids" value="${cardType.addValids!}" req="赠送有效期" size="8" maxlength="6"></td>
          <th>单位</th>
          <td><select name="addValidUnit"><#if timeUnit??><#list timeUnit as t><option value="${t.id}"<#if cardType.addValidUnit?? && cardType.addValidUnit=t.id> selected</#if>>${t.name}</option></#list></#if></select></td>
        </tr>
        <tr>
          <th>启用期限</th>
          <td><input type="text" name="openPeriod" value="${cardType.openPeriod!}" req="启用期限" size="8" maxlength="6"></td>
          <th>次数</th>
          <td><input type="text" name="degree" value="${cardType.degree!}" req="次数" size="8" maxlength="6"></td>
        </tr>
        <tr>
          <th>超过时间<br>扣除次数</th>
          <td><input type="text" name="deductQuantity" value="${cardType.deductQuantity!}" size="8" maxlength="6"></td>
          <td colspan="2"><label><input type="checkbox" class="cb" name="noBusyCard" value="1"<#if cardType.noBusyCard?? && cardType.noBusyCard=1> checked</#if>>非繁忙时段次卡</label></td>
        </tr>
        <tr>
          <th></th>
          <td><label><input type="checkbox" class="cb" name="timeLock" value="1"<#if cardType.timeLock?? && cardType.timeLock=1> checked</#if>>时段限制</label></td>
          <td colspan="2"><label><input type="checkbox" class="cb" name="degreeLock" value="1"<#if cardType.degreeLock?? && cardType.degreeLock=1> checked</#if>>次数限制/周</label></td>
        </tr>
        <tr>
          <th>额度卡</th>
          <td colspan="3"><div id="div_pic"><#if cardType.quotaCardPic?? && cardType.quotaCardPic?length!=0><img src="${_picPath!}${cardType.quotaCardPic!}" height="80"/></#if></div>
            <input type="hidden" name="quotaCardPic" value="${cardType.quotaCardPic!}" />
            <input type="button" class="opwin" value="上传图片..." onmouseover="setupl(this);"/>
            <input type="button" class="opwin" value="取消额度卡" onclick="cancelQuotaCard();"/></td>
        </tr>
      </table>

      <table class="input">
        <caption style="margin-top:20px; padding-top:10px; border-top:1px solid #ccc;">价格设置</caption>
        <tr>
          <th width="23%">基本价格</th>
          <td width="24%"><input type="text" name="price" value="${cardType.price!}" req="基本价格" size="8" maxlength="6"></td>
          <th width="25%">补卡费</th>
          <td width="28%"><input type="text" name="mendFee" value="${cardType.mendFee!}" req="补卡费" size="8" maxlength="6"></td>
        </tr>
        <tr>
          <th>停卡费</th>
          <td><input type="text" name="stopFee" value="${cardType.stopFee!}" req="停卡费" size="8" maxlength="6"></td>
          <th>新会员工本费</th>
          <td><input type="text" name="newFixedFee" value="${cardType.newFixedFee!}" req="新会员工本费" size="8" maxlength="6"></td>
        </tr>
        <tr>
          <th>转卡费</th>
          <td><input type="text" name="changeFee" value="${cardType.changeFee!}" req="转卡费" size="8" maxlength="6"></td>
          <th>老会员工本费</th>
          <td><input type="text" name="oldFixedFee" value="${cardType.oldFixedFee!}" req="老会员工本费" size="8" maxlength="6"></td>
        </tr>
        <tr>
          <th>转店费</th>
          <td><input type="text" name="chgShopFee" value="${cardType.chgShopFee!}" req="转店费" size="8" maxlength="6"></td>
          <th>续费折扣</th>
          <td><input type="text" name="contDiscount" value="${cardType.contDiscount!}" req="续费折扣" size="8" maxlength="6"></td>
        </tr>

        <tr>
          <th>Inbody体验</th>
          <td><input type="text" name="amortizeFee1" value="${cardType.amortizeFee1!}" size="8" maxlength="6"></td>
          <th>健身计划</th>
          <td><input type="text" name="amortizeFee2" value="${cardType.amortizeFee2!}" size="8" maxlength="6"></td>
        </tr>
        <tr>
          <th>PT课程1节</th>
          <td><input type="text" name="amortizeFee3" value="${cardType.amortizeFee3!}" size="8" maxlength="6"></td>
          <th>赠品包</th>
          <td><input type="text" name="amortizeFee4" value="${cardType.amortizeFee4!}" size="8" maxlength="6"></td>
        </tr>
        <tr>
          <th>赠送卡</th>
          <td colspan="3"><select name="giftCardType" style="width:300px;"><option value="无"></option><#if giftCardType??><#list giftCardType as t><option value="${t.id}"<#if cardType.giftCardType?? && cardType.giftCardType=t.id> selected</#if>>${t.id} - ${t.name!}</option></#list></#if></select></td>
        </tr>
        <tr>
          <th style="height:25px;"></th>
          <td colspan="3" style="line-height:120%;"><label><input type="checkbox" name="presentPt" value="1"<#if cardType.presentPt?? && cardType.presentPt=1> checked</#if>>赠送1节私教合同</label></td>
        </tr>
      </table>

      <table class="input">
        <caption style="margin-top:20px; padding-top:10px; border-top:1px solid #ccc;">通店详细设置</caption>
        <tr>
          <th>可选择门店数量</th>
          <td><input type="text" name="manyShopQuantity" value="${cardType.manyShopQuantity!}" req="可选择门店数量" size="8" maxlength="6"></td>
        </tr>
        <tr>
          <td></td>
          <td style="line-height:120%"><label><input type="checkbox" class="cb" name="allowAddShop" value="1"<#if cardType.allowAddShop?? && cardType.allowAddShop=1> checked</#if>>允许增加门店</label></td>
        </tr>
        <tr>
          <th>增加门店需要费用</th>
          <td><input type="text" name="addShopFee" value="${cardType.addShopFee!}" size="8" maxlength="6"></td>
        </tr>
      </table>

      <table class="input">
        <caption style="margin-top:20px; padding-top:10px; border-top:1px solid #ccc;">二维码设置</caption>
        <tr>
          <td style="line-height:120%"><label><input type="checkbox" class="cb" name="barcodeUse" value="1"<#if cardType.barcodeUse?? && cardType.barcodeUse=1> checked</#if>>二维码专用</label></td>
        </tr>
        <tr>
          <td style="line-height:120%"><label><input type="checkbox" class="cb" name="barcodeNoContract" value="1"<#if cardType.barcodeNoContract?? && cardType.barcodeNoContract=1> checked</#if>>单次/多次体验不办合同</label></td>
        </tr>
        <tr>
          <td style="line-height:120%"><label><input type="checkbox" class="cb" name="barcodeContract" value="1"<#if cardType.barcodeContract?? && cardType.barcodeContract=1> checked</#if>>体验类型办理合同</label></td>
        </tr>
        <tr>
          <td><input type="text" name="barcodeMonth" value="${cardType.barcodeMonth!}" size="3" maxlength="3">个月内,
            可以购买<input type="text" name="barcodeQuantity" value="${cardType.barcodeQuantity!}" size="3" maxlength="3">次</td>
        </tr>
      </table>

    </div>
    <div class="button"><input type="submit" value="提 交"></div>
  </form>
</div>

<div class="lfls" style="width:400px; float:left; margin-left:20px;">
  <div class="kbox" style="padding-top:0;">
    <div class="lsinfo">入场时段限制</div>
    <table class="list">
      <tr>
        <th width="25%">日期编码</th>
        <th width="23%">状态</th>
        <th width="20%">开始时间</th>
        <th width="20%">结束时间</th>
        <th></th>
      </tr>
    </table>
    <div style="max-height:290px; overflow-y:auto; overflow-x:hidden;">
      <table id="tb_time" class="list"><#if timeList??><#list timeList as c>
        <tr<#if c_index%2==1> class="line2"<#else> class="line1"</#if> aid="${c.autoId!}">
          <td><select><option value=""></option><#if dayCode??><#list dayCode as t><option value="${t.id}" <#if c.dayId=t.id>selected</#if>>${t.name}</option></#list></#if></select></td>
          <td><select><option value="1" <#if c.status=1>selected</#if>>限制</option><option value="2" <#if c.status=2>selected</#if>>不限制</option></select></td>
          <td><input type="text" value="${c.beginTime}" size="5" maxlength="5"></td>
          <td><input type="text" value="${c.endTime}" size="5" maxlength="5"></td>
          <td><img src="${_appPath!}/images/del.png" onclick="deli(this);" style="cursor:pointer;"/></td>
        </tr></#list></#if>
      </table>
    </div>
    <div><a href="javascript:addtm();" class="addline">增加一行</a></div>

    <div class="lsinfo">门店级别设置</div>
    <table class="list">
      <tr>
        <th width="60%">门店级别</th>
        <th width="40%">折扣</th>
        <th></th>
      </tr>
    </table>
    <div style="max-height:290px; overflow-y:auto; overflow-x:hidden;">
      <table id="tb_level" class="list"><#if levelList??><#list levelList as c>
        <tr<#if c_index%2==1> class="line2"<#else> class="line1"</#if> aid="${c.autoId!}">
          <td class="left"><select style="width:200px;"><option value=""></option><#if shopLevel??><#list shopLevel as t><option value="${t.id}" <#if c.levelCode=t.id>selected</#if>>${t.id} - ${t.name}</option></#list></#if></select></td>
          <td><input type="text" value="${c.discount}" size="8" maxlength="8"></td>
          <td><img src="${_appPath!}/images/del.png" onclick="deli(this);" style="cursor:pointer;"/></td>
        </tr></#list></#if>
      </table>
    </div>
    <div><a href="javascript:addlv();" class="addline">增加一行</a></div>

    <div class="lsinfo">销量折扣设置</div>
    <table class="list">
      <tr>
        <th width="30%">数量下限</th>
        <th width="30%">数量上限</th>
        <th width="30%">折扣</th>
        <th></th>
      </tr>
    </table>
    <div style="max-height:290px; overflow-y:auto; overflow-x:hidden;">
      <table id="tb_quan" class="list"><#if quanList??><#list quanList as c>
        <tr<#if c_index%2==1> class="line2"<#else> class="line1"</#if> aid="${c.autoId!}">
          <td><input type="text" value="${c.amount}" size="8" maxlength="6"></td>
          <td><input type="text" value="${c.amount2}" size="8" maxlength="6"></td>
          <td><input type="text" value="${c.discount}" size="8" maxlength="8"></td>
          <td><img src="${_appPath!}/images/del.png" onclick="deli(this);" style="cursor:pointer;"/></td>
        </tr></#list></#if>
      </table>
    </div>
    <div><a href="javascript:addqn();" class="addline">增加一行</a></div>

    <div class="lsinfo">多人卡设置</div>
    <table class="list">
      <tr>
        <th width="20%">使用人类型</th>
        <th width="20%">使用人数量</th>
        <th width="25%">增加费用/人</th>
        <th width="25%">是否可以增加</th>
      </tr>
    </table>
    <div style="max-height:290px; overflow-y:auto; overflow-x:hidden;">
      <table id="tb_user" class="list"><#if userList??><#list userList as c>
        <tr<#if c_index%2==1> class="line2"<#else> class="line1"</#if> aid="${c.autoId!}">
          <td><select><option value=""></option><#if useType??><#list useType as t><option value="${t.id}" <#if c.useType=t.id>selected</#if>>${t.name}</option></#list></#if></select></td>
          <td><input type="text" value="${c.useQuantity}" size="4" maxlength="4"></td>
          <td><input type="text" value="${c.fee}" size="8" maxlength="8"></td>
          <td><label><input type="checkbox" value="1" <#if c.canAddPerson==1>checked</#if>>是</label></td>
          <td><img src="${_appPath!}/images/del.png" onclick="deli(this);" style="cursor:pointer;"/></td>
        </tr></#list></#if>
      </table>
    </div>
    <div><a href="javascript:addus();" class="addline">增加一行</a></div>

  </div>
</div>
<script type="text/javascript" src="${_appPath!}/js/upload2.js"></script>
<script type="text/javascript">initUpl("_upload");</script>
<script type="text/javascript">
  function uploadSucc(data) {
    var div = document.getElementById("div_pic");
    div.innerHTML = '<img src="${_picPath!}'+data.furl+'" height="80">';
    document.getElementById("fm_input").quotaCardPic.value = data.furl;
  }
  function cancelQuotaCard() {
    var div = document.getElementById("div_pic");
    div.innerHTML = '';
    document.getElementById("fm_input").quotaCardPic.value = "";
  }
</script>
</@page.html>